package com.hjl.sessions; /**
 * @author ServivE
 * @className ${NAME}
 * @description ${description}
 * @version 0.1
 * @date 2024/7/27 16:02
 * @since jdk11
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "GetValueServlet", value = "/getValue")
public class GetValueServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //通过request对象获取session对象
        HttpSession session = request.getSession();
        //取值
        //返回的是对象类型，强转为String
        String username = (String) session.getAttribute("username");
        String username2 = (String) request.getAttribute("username");
        System.out.println("通过session取到了一个值" + username);
        System.out.println("通过request取到了一个值" + username2);
    }
}
